#!/usr/bin/env python
# -*- coding:utf-8 -*- 
# Author: MapzChen
# Email: 61966578@qq.com

from flask import Flask
from flask import jsonify
from flask import current_app
from flask_cors import *


import random

app = Flask(__name__)

CORS(app, supports_credentials=True)

with app.app_context():
    # 在本代码块中， current_app 指向应用。
    print(current_app.name)
    all_the_text = open('words.txt',encoding='utf8').read()
    current_app.words = [s.strip() for s in  all_the_text.split(' ')]
    # print(current_app.words)

@app.route('/randomWords<count>')
def sayHello(count):
    count = int(count)
    cur_count = 0
    cur_list = []
    while cur_count < count:
        cur_list.append(current_app.words[random.randrange(0,len(current_app.words))])
        cur_count += 1

    return jsonify(cur_list)

if __name__ == '__main__':
    app.run(debug=True)